read.csv(file = "data/island_veg_data_raw.csv", header=T)
read.csv(file = "data/island_veg_data_raw.csv", header=T)
# The file argument is where the directory of the file,
# the header=T just indicates that you have column names in the header
# if you don't then make sure to put header as F or the first row of data
# will become your column names. The default is header=T, so you can also
# more simply write this as:
read.csv("data/island_veg_data_raw.csv")
my_data <- read.csv("data/island_veg_data_raw.csv")
# and when looking at our data:
head(my_data)
# 1) Upload the dataset called "turtle_nesting_data.csv" from the data folder and save it to a
# dataframe variable called bumble_data:
turtle_data <- read.csv("data/turtle_nesting_data.csv")
# 1) Upload the dataset called "turtle_nesting_data.csv" from the data folder and save it to a
# dataframe variable called bumble_data:
turtle_data <- read.csv("data/turtle_nesting_data.csv")
# 2) View just the top few rows of data in this new dataframe to make sure the data looks
# the way you would expect it:
head(turtle_data)
# 3) Upload your own dataset and save it to a variable.
read.csv()
# 5) How many columns do your data have and what are they called?
ncol()
length()
names()
# 6) How many rows of data do you have?
nrow()
# So let's upload the "avian_mating_data_clean.csv" file:
avian_data <- read.csv("data/avian_mating_data_clean.csv")
# So let's upload the "avian_mating_data_clean.csv" file:
avian_data <- read.csv("data/avian_mating_data_clean.csv")
# Quick peek at it:
head(avian_data)
# To see how many rows of data we have, we can use nrow
nrow(avian_data) # The actual data has way more, but I subset it for simplicity here.
###################################
##### THE 'plot()' and 'hist()' FUNCTIONS
# The most common and basic function you will use when plotting is plot()
# It can take many arguments,
# but for now the key arguments are the x values and y values.
# let's get those values from our data. Let's first visualize the relationship
# between female bodymass and egg size:
egg_mass <- avian_data$egg_mass_g
female_mass <- avian_data$female_bodymass_g
plot(x=female_mass, y=egg_mass)
# A quicker and neater way of entering the arguments into the plot function are to
# tell it the source of the dataframe where we are storing the data.
# Then you can just use the variable names from your dataframe in the form
# of a formula:
plot(egg_mass_g ~ female_bodymass_g, data=avian_data)
# Now what about clutch size and egg mass. Maybe the larger the clutch size (more eggs)
# means that each egg is smaller, a tradeoff in energy allocation to the eggs?
# Pause the video and try it yourself. If you forget the name of the column you want to
# plot, you can always use the names function:
names(avian_data)
plot(egg_mass_g ~ clutch_size, data=avian_data)
# egg mass data appear to be quite clustered.
# We can visualize this a bit more clearly by drawing a histogram of egg mass values:
hist(avian_data$egg_mass_g)
# indeed it appears to be quite skewed.
# let's try log-transforming those values to bring them closer to something easier to
# visualize:
hist(log(avian_data$egg_mass_g))
# So now let's log transform egg mass in the scatterplot:
plot(log(egg_mass_g) ~ clutch_size, data=avian_data)
# if we look at our data:
head(avian_data)
# we can see that mating system is a categorical variable.
# let's look at differences in egg mass with respect to mating system:
# First, let's see how many values there are for each mating system in the data:
# remember, the table function allows us to tabitulate and count the categories
table(avian_data$mating_system)
boxplot(log(egg_mass_g) ~ mating_system, data=avian_data)
turtle_data <- read.csv("data/turtle_nesting_data.csv")
head(turtle_data)
# First let's visualize if there is an association between veg cover and
# nest predation. But first let's look at the veg_cover data with a histogram:
hist(turtle_data$veg_cover) # doesn't look too bad!
# and let's double check that nest predation is either a 1 or a zero:
table(turtle_data$nest_predation)
plot(nest_predation ~ veg_cover, data = turtle_data)
# Because there are many overlapping points, it's difficult to visualize this clearly,
# but we can use the jitter() function to randomly shake the points up a bit to visualize
# this a bit more clearly.
# I'm just using the jitter function right in the plot function:
plot(jitter(nest_predation) ~ veg_cover, data = turtle_data)
# We can also zoom in on parts of the data by changing the x and y limits
plot(jitter(nest_predation) ~ veg_cover, data = turtle_data, xlim=c(0,20))
# So it appears like there is a greater chance for predation below 15% cover.
# Similarly we can see this on the high end, after about 80% cover:
plot(jitter(nest_predation) ~ veg_cover, data = turtle_data, xlim=c(70,100))
# Next let's look at how survival changes from year to year:
plot(nest_survival ~ year, data = turtle_data)
# again there are many overlapping points,
# so let's make this a bit easier to see by jittering:
plot(jitter(nest_survival) ~ year, data = turtle_data)
plot(jitter(nest_survival) ~ jitter(year), data = turtle_data)
# Let's calculate the proportion of surviving nests within each year and plot that.
# First, let's pull out the vectors for year and nest_survival
year <- turtle_data$year
nest_survival <- turtle_data$nest_survival
# Now we can use the tapply function to apply the mean to nest survival, within each year:
prop_surviving <- tapply(X = nest_survival, FUN = function(x) mean(x, na.rm=T), INDEX = year)
# So now let's prepare these data for plotting:
year_unique <- names(prop_surviving)
# Because the years were a character vector (as can be seen by the ""s) we
# can convert it back to numeric with the as.numeric() function:
year_unique <- as.numeric(year_unique)
# and build a new dataframe with these data:
surv_data <- data.frame(years = year_unique, prop_surviving = prop_surviving)
# Now plot it:
plot(prop_surviving ~ years, data=surv_data)
# let's make this look a bit better by making it a line plot:
plot(prop_surviving ~ years, data=surv_data, type="l")
# Finally, let's add this line to the original plot we had using the points function:
plot(jitter(nest_survival) ~ jitter(year), data = turtle_data)
points(prop_surviving ~ years, data=surv_data, type="l")
# Let's load the turtle data again:
turtle_data <- read.csv("data/turtle_nesting_data_clean.csv")
head(turtle_data)
# Let's load the turtle data again:
turtle_data <- read.csv("data/turtle_nesting_data_clean.csv")
head(turtle_data)
# Remember we can add a new column to our data using the $ operator:
# but let's first save our modified version of the data under a new name:
turtle_mod <- turtle_data
turtle_mod$prop_surv <- turtle_data$live_hatchlings / turtle_data$clutch_size
# Now let's double check that this gives us what we want by displaying a quick
# histogram. Prop_surviving should fall between 0 and 1:
hist(turtle_mod$prop_surv)
# We can't just say != NA
turtle_mod <- turtle_mod[!is.na(turtle_mod$prop_surv), ]
turtle_mod <- turtle_mod[turtle_mod$prop_surv > 0, ]
# Lets check again with the hist function now that zeros are removed:
hist(turtle_mod$prop_surv)
# Let's also remove that weird outlier
turtle_mod <- turtle_mod[turtle_mod$prop_surv <= 1]
# 1) Upload the data "island_soil_data_raw.csv" located in the "data" folder and explore the data a bit:
soil_data <- read.csv("data/island_soil_data_raw.csv")
# 1) Upload the data "island_soil_data_raw.csv" located in the "data" folder and explore the data a bit:
soil_data <- read.csv("data/island_soil_data_raw.csv")
head(soil_data)
nrow(soil_data)
soil_data
# 2) Make a simple scatterplot of of the relationship between Clay_perc and Sand_perc:
plot(Clay_perc ~ Sand_perc, data=soil_data)
# 3) Now clean up this plot to make it look nice by adjusting the axis names, making the points larger
# and filled in, and any other adjustments you'd like to make to increase the visual appeal and
# presentability of this figure:
plot(Clay_perc ~ Sand_perc, data=soil_data, xlab="Percent Sand", ylab="Percent Clay", pch=16, cex=1.5)
# Since they are both the same type of unit, I decided to make scale both axes with the same aspect ratio:
plot(Clay_perc ~ Sand_perc, data=soil_data, xlab="Percent Sand", ylab="Percent Clay", pch=16, cex=1.5, asp=1)
# 4) Upload the data "island_spatial_data_raw.csv" located in the "data" folder and explore the data a bit.
# View histograms of the the continuous variables in this new dataframe.
spatial_data <- read.csv("data/island_spatial_data_raw.csv")
head(spatial_data)
nrow(spatial_data)
str(spatial_data)
# 4) Upload the data "island_spatial_data_raw.csv" located in the "data" folder and explore the data a bit.
# View histograms of the the continuous variables in this new dataframe.
spatial_data <- read.csv("data/island_spatial_data_raw.csv")
head(spatial_data)
nrow(spatial_data)
str(spatial_data)
hist(spatial_data$AREA_HA)
hist(spatial_data$DIST_M)
# 5) Now add the two new columns of spatial data to our other dataframe of soil data.
# Hint, make sure that both dataframes are ordered by island to ensure that
# the new columns you add are in the right order.
soil_data <- soil_data[order(soil_data$island),]
spatial_data <- spatial_data[order(spatial_data$ISLAND),]
island_data <- soil_data
island_data$area_ha <- spatial_data$AREA_HA
island_data$distance_m <- spatial_data$DIST_M
island_data
# 6) View a histogram of island areas to see if there is a good cutoff
# between larger and smaller islands:
hist(island_data$area_ha)
# 7) It's difficult to tell from the histogram and since we only have
# 20 islands, just sort and then plot island area as a function of 1 to show them all
plot(sort(area_ha) ~ 1, data=island_data)
# 8) Do the same for island distance (isolation from the mainland shorline)
plot(sort(distance_m) ~ 1, data=island_data)
island_data$big_island <- island_data$area_ha > 0.65
island_data$far_island <- island_data$distance_m > 350
island_data
boxplot(Clay_perc ~ big_island, data=island_data)
plot(Clay_perc ~ area_ha, data=island_data)
boxplot(Clay_perc ~ big_island, data=island_data, xaxt="n",
ylab="", xlab="")
title(main = list("Island Soil Texture Boxplot", cex = 1.5,
col = "black", font = 2),
ylab = list("Clay %", cex=1.3))
axis(side = 1, at=c(1:2), labels = c("Small islands","Large islands"), cex.axis=1.2)
plot(Clay_perc ~ area_ha, data=island_data,
ylab="", xlab="", cex=1.4, pch=16)
title(main = list("Island Soil Texture Scatter", cex = 1.5,
col = "black", font = 2),
ylab = list("Clay %", cex=1.3),
xlab = list("Island area (ha)", cex=1.3))
# 11) Now save these plots.
pdf("clay_boxplot.pdf", width=4.5, height=4)
boxplot(Clay_perc ~ big_island, data=island_data, xaxt="n",
ylab="", xlab="")
title(main = list("Island Soil Texture Boxplot", cex = 1.5,
col = "black", font = 2),
ylab = list("Clay %", cex=1.3))
axis(side = 1, at=c(1:2), labels = c("Small islands","Large islands"), cex.axis=1.1)
dev.off()
pdf("clay_scatter.pdf", width=4.5, height=4)
plot(Clay_perc ~ area_ha, data=island_data,
ylab="", xlab="", cex=1.4, pch=16)
title(main = list("Island Soil Texture Scatter", cex = 1.5,
col = "black", font = 2),
ylab = list("Clay %", cex=1.3),
xlab = list("Island area (ha)", cex=1.3))
dev.off()
# Let's upload the avian data from our previous lesson, but this time
# the original raw data that includes everything:
avian_data_raw <- read.csv("data/avian_mating_data_raw.csv")
# Let's upload the avian data from our previous lesson, but this time
# the original raw data that includes everything:
avian_data_raw <- read.csv("data/avian_mating_data_raw.csv")
avian_data_raw
# Just use read_csv() same as before but with an underscrore:
avian_data_raw <- read_csv("data/avian_mating_data_raw.csv")
library("tidyverse")
# Just use read_csv() same as before but with an underscrore:
avian_data_raw <- read_csv("data/avian_mating_data_raw.csv")
avian_data_raw
# First, read in the data "island_veg_data_raw.csv":
island_plants <- read_csv("data/island_veg_data_raw.csv")
# So let's select only columns of interest, renaming for clarity
# and to lowercase for consistency and then filtering
# for the overstory data:
overstory_data <- select(island_plants, island = Island, plot = Plot, date = `Date (mm/dd/yy)`,
covertype = CoverType, species = Species, diameter_cm = Over_Midstory)
overstory_data <- filter(overstory_data, covertype == "overstory")
overstory_data <- select(overstory_data, -covertype)
overstory_data
tree_data_fin <- mutate(overstory_data,
trunk_area_cm2 = pi*(diameter_cm/2)^2, # calculate area in cm2
trunk_area_m2 = trunk_area_cm2 * 0.0001) # convert to area in m2
tree_data_fin
# and then remove the columns we don't need anymore:
tree_data_fin <- select(tree_data_fin, -trunk_area_cm2, -diameter_cm)
tree_data_fin
# as you are making the function
# create a temporary variable for spp_name to test it out:
spp_name <- "pinus taeda"
cap_genus <- function(spp_name) {
# 1)
first_letter <- substr(spp_name, start=1, stop=1) #extract the first letter
# 2)
rest_of_name <- substr(spp_name, start=2, stop=nchar(spp_name)) # extract the rest
# 3)
first_let_cap <- toupper(first_letter)
# 4)
new_name <- paste(first_let_cap, rest_of_name, sep="")
# 5)
return(new_name)
}
# First make sure to select and run this entire function so that it gets stored in the environment
cap_genus("pinus taeda")
cap_genus("elymus repens")
tree_data_fin <- mutate(tree_data_fin, species = cap_genus(species))
# First, take a quick look at the histogram of tree sizes:
hist(tree_data_fin$trunk_area_m2, breaks=20)
# We'll use a very versatile function called the ifelse function.
# The first argument of the ifelse function is a logical statement. Then the next
# argument is the value when it's true, and the following is the value when it's
# false:
tree_data_fin <- mutate(tree_data_fin, tree_size = ifelse(trunk_area_m2 < 0.1, "small", "large"))
tree_data <- select(island_plants, island = Island, plot = Plot, date = `Date (mm/dd/yy)`,
covertype = CoverType, species = Species, diameter_cm = Over_Midstory) %>%
# Instead of having to reassign the dataframe each time... * SHOW EXAMPLE *...
# keep only overstory trees
filter(covertype == "overstory") %>%
select(-covertype) %>%
# calculate trunk area in meters squared of each tree
mutate(trunk_area_cm2 = pi*(diameter_cm/2)^2,
trunk_area_m2 = trunk_area_cm2 * 0.0001) %>%
# remove unnecessary columns
select(-trunk_area_cm2, -diameter_cm) %>%
# capitalize all genera in the scientific names
mutate(species = cap_genus(species),
# add column that indicates if the trees are small or large
tree_size = ifelse(trunk_area_m2 < 0.1, "small", "large"))
# %>% basically takes the resulting dataframe generated before it and
# uses it as the first argument in the function that follows. This way
# you can string together an entire pipeline of functions that modify
# and prepare the data in one go. You only need to supply the source data
# once. And you can still add comments at each step to indicate what is happening.
tree_data
# first select columns of interest
understory_data <- select(island_plants, island = Island, species=Species,
north=`Cover N`, east=`Cover E`, south=`Cover S`, west=`Cover W`) %>%
# capitalize genera:
mutate(species = cap_genus(species)) %>%
# filter out all the NAs
filter(!is.na(north))
understory_data
# For example, looking at our tree data
tree_data
# First we split the data using the group_by function:
tree_summary <- group_by(tree_data, species, island) %>% #just the groups that you want to apply each function by
# * show how when running just this group_by, nothing changes, but the tibble knows the groupings--show this *
# then use the summarize function to calculate the basal area of each group:
summarize(mean_BA_ha = sum(trunk_area_m2)/0.05) %>%
# It's good practice after using the group_by function to always add ungroup() at the end of your
# pipeline. This won't change your output, but it may lead to errors down the line if you forget
# that your data were grouped.
ungroup()
tree_summary
# Let's also see how many trees were available for each island mean basal area estimate:
tree_summary <- group_by(tree_data, species, island) %>%
summarize(mean_BA_ha = sum(trunk_area_m2)/0.05,
trees_per_samp = n()) %>% #n() just returns the number of rows/observations within each grouping
ungroup()
tree_rel_size <- group_by(tree_data, island) %>% # group by island
mutate(relative_size = proportions(trunk_area_m2))
# So if we extract just one island:
island_15 <- filter(tree_rel_size, island==15)
# the all the proportions of total basal area for each species should sum to 1
sum(island_15$relative_size)
# It's good practice to double check yourself like that just to make sure that the
library(tidyverse)
island_plants <- read_csv("data/island_veg_data_raw.csv")
island_soil <- read_csv("data/island_soil_data_raw.csv")
island_spatial <- read_csv("data/island_spatial_data_raw.csv")
island_plants <- read_csv("data/island_veg_data_raw.csv")
island_soil
tree_BA_data
tree_BA_soil <- left_join(x = tree_BA_data, y = island_soil, by = "island")
tree_BA_soil
library(tidyverse)
island_plants <- read_csv("data/island_veg_data_raw.csv")
### Add our uppercase first letter of scientific name function from before:
cap_genus <- function(spp_name) {
first_letter <- substr(spp_name, start=1, stop=1) #extract the first letter
rest_of_name <- substr(spp_name, start=2, stop=nchar(spp_name)) # extract the rest
first_let_cap <- toupper(first_letter)
new_name <- paste(first_let_cap, rest_of_name, sep="")
return(new_name)
}
tree_BA_data <- select(island_plants, island = Island, plot = Plot, date = `Date (mm/dd/yy)`,
covertype = CoverType, species = Species, diameter_cm = Over_Midstory) %>%
# keep only overstory trees
filter(covertype == "overstory") %>%
select(-covertype) %>%
# calculate trunk area in meters squared of each tree
mutate(trunk_area_cm2 = pi*(diameter_cm/2)^2,
trunk_area_m2 = trunk_area_cm2 * 0.0001) %>%
# remove unnecessary columns
select(-trunk_area_cm2, -diameter_cm) %>%
# capitalize all genera in the scientific names
mutate(species = cap_genus(species),
# add column that indicates if the trees are small or large
tree_size = ifelse(trunk_area_m2 < 0.1, "small", "large")) %>%
group_by(species, island) %>%
summarize(mean_BA_ha = sum(trunk_area_m2)/0.05,
trees_per_samp = n()) %>%
ungroup()
tree_BA_data
island_soil <- read_csv("data/island_soil_data_raw.csv")
island_spatial <- read_csv("data/island_spatial_data_raw.csv")
island_soil
island_spatial
island_soil
tree_BA_data
tree_BA_soil <- left_join(x = tree_BA_data, y = island_soil, by = "island")
tree_BA_soil
# Now let's add the island spatial data:
# We'll use the left join again, but if we look at the spatial data,
island_spatial
tree_BA_all <- left_join(tree_BA_soil, island_spatial, by="island")
tree_BA_all <- left_join(tree_BA_soil, island_spatial, by=c("island"="ISLAND"))
# left side of the equals is what the column is called in the first dataset
# and the right of the equals is what it is named in the second dataset.
tree_BA_all
# I won't go over them here, but if you search the *_join function help
# page:
?left_join()
library(tidyverse)
island_plants <- read_csv("data/island_veg_data_raw.csv")
island_soil <- read_csv("data/island_soil_data_raw.csv")
island_spatial <- read_csv("data/island_spatial_data_raw.csv")
library(tidyverse)
covers_data_all <- read_csv("data/lesson_13_dataframe.csv")
library(tidyverse)
covers_data_all <- read_csv("data/lesson_13_dataframe.csv")
library(tidyverse)
island_plants <- read_csv("data/island_veg_data_raw.csv")
island_soil <- read_csv("data/island_soil_data_raw.csv")
island_spatial <- read_csv("data/island_spatial_data_raw.csv")
# We'll define a function to use for capitalizing the genus of
# each scientific species name as we did in a previous lesson:
### Define function to capitalize first letter of each scientific name:
cap_genus <- function(spp_name) {
first_letter <- substr(spp_name, start=1, stop=1) #extract the first letter
rest_of_name <- substr(spp_name, start=2, stop=nchar(spp_name)) # extract the rest
first_let_cap <- toupper(first_letter)
new_name <- paste(first_let_cap, rest_of_name, sep="")
return(new_name)
}
# also define the function that converts cover classes to actual
# cover values:
class2value <- function(cover_classes){
# use case_when function to assign the cover appropriate value
cover_value = case_when(cover_classes == 1 ~ 0.5,
cover_classes == 2 ~ 10.5,
cover_classes == 3 ~ 20.5,
cover_classes == 4 ~ 38,
cover_classes == 5 ~ 63,
cover_classes == 6 ~ 88)
# and return those values:
return(cover_value)
}
# first, filter to only midstory or understory covers:
clean_data_1 <- filter(island_plants, CoverType == "midstory" | CoverType == "understory") %>%
# and select and rename the varables we want to keep:
select(island = Island, plot = Plot, date = `Date (mm/dd/yy)`, species = Species,
covertype = CoverType,
cover_mid = Over_Midstory,
cover_N = `Cover N`,
cover_E = `Cover E`,
cover_S = `Cover S`,
cover_W = `Cover W`) %>%
# Now clean up the species names by capitalizing the genus on each:
mutate(species = cap_genus(species)) %>%
# then convert cover values to actual percent covers:
mutate(across(cover_mid:cover_W, class2value)) %>%
# convert NAs to zeros:
mutate(cover_N = ifelse(covertype=="understory" & is.na(cover_N), 0, cover_N),
cover_E = ifelse(covertype=="understory" & is.na(cover_E), 0, cover_E),
cover_S = ifelse(covertype=="understory" & is.na(cover_S), 0, cover_S),
cover_W = ifelse(covertype=="understory" & is.na(cover_W), 0, cover_W),
# calculate mean cover per plot:
cover_under = (cover_N + cover_E + cover_S + cover_W) / 4) %>%
# remove the subplot columns:
select(-(cover_N:cover_W)) %>%
# combine the two columns of understory and midstory cover into one column, to remove NAs
# using the coalesce function:
mutate(cover = coalesce(cover_mid, cover_under)) %>%
# then remove the mid and understory columns:
select(-(cover_mid:cover_under)) %>%
# Then fix the error that there may be species X plot X covertype duplicates
# because I accidentally recorded the same species twice in the same covertype in the same plot
# Fix this by merging and averaging any duplicate rows:
# Group by species, plot, and covertype:
group_by(island, plot, species, covertype) %>%
# then merge these duplicates into their mean:
summarize(cover = mean(cover, na.rm=T)) %>%
# always good practice to ungroup
ungroup() %>%
# Now use the pivot_wider function to reshape the dataframe back into separate
# columns for each covertype, ensuring one row per observation:
pivot_wider(names_from = covertype, values_from = cover, values_fill = 0) %>%
# summarize results to the mean covers per species and island by grouping by species and island:
group_by(island, species) %>%
summarize(understory = mean(understory), midstory = mean(midstory)) %>%
ungroup()
# Now need to start a new dataframe in order to fill in the implicitly
# missing values (i.e., all species X island combinations):
# Do this using the complete function, and then the expand function within it.
clean_data_2 <-  complete(clean_data_1, expand(clean_data_1, island, species),
fill=list(understory=0, midstory=0)) %>%
# now join the environmental data:
left_join(island_spatial, by=c("island"="ISLAND")) %>%
left_join(island_soil) %>%
# and do some final column name adjustments:
rename(area_ha = AREA_HA, distance_m = DIST_M, clay = Clay_perc, silt = Silt_perc, sand = Sand_perc)
# and redefine the variable:
cleaned_data <- clean_data_2
cleaned_data
V_corymbosum <- filter(cleaned_data, species == "Vaccinium corymbosum")
plot(understory ~ sand, data=V_corymbosum, pch=16, cex=1.5, col=2,
xlab = "Soil Sand (%)", ylab = "Highbush Blueberry Understory Cover (%)")
plot(understory ~ clay, data=V_corymbosum, pch=16, cex=1.5, col=2,
xlab = "Soil Clay (%)", ylab = "Highbush Blueberry Understory Cover (%)")
plot(midstory ~ sand, data=V_corymbosum, pch=16, cex=1.5, col=4,
xlab = "Soil Sand (%)", ylab = "Highbush Blueberry Midstory Cover (%)")
plot(midstory ~ clay, data=V_corymbosum, pch=16, cex=1.5, col=4,
xlab = "Soil Clay (%)", ylab = "Highbush Blueberry Midstory Cover (%)")
ff_data_raw <- read_csv("data/first_flower_data.csv")
ff_data_raw <- read_csv("data/first_flower_data.csv")
# a quick view of the data
ff_data_raw
mammal_exc_veg <- read_csv("data/mammal_exc_vegetation.csv")
# 1) Load the package "tidyverse"
library(tidyverse)
mammal_exc_veg <- read_csv("data/mammal_exc_vegetation.csv")
mammal_exc_veg_clean <- select(mammal_exc_veg, -SURVEY, -YEAR, month=MONTH, site=SITE, block=BLOCK, treatment=TREATMENT,
plot=PLOT, subplot=COORDINATE, bare_ground=BARE_GROUND)
# First here is the code to load and cleanup the mammal exclosure vegetation data from the previous excercise file:
library(tidyverse)
mammal_exc_veg <- read_csv("data/mammal_exc_vegetation.csv")
# Now also load the mammal exclosure habitat data "mammal_exc_habitat.csv":
mammal_exc_hab <- read_csv("data/mammal_exc_habitat.csv")
sample(1:256, rep=T, 10000)
gene1 <- sample(1:256, rep=T, 10000)
gene1 <- sample(1:256, rep=T, 10000)
gene2 <- sample(1:256, rep=T, 10000)
gene1 <= 128
sum(gene1 <= 128 & gene2 <= 128)/10000
gene1 <- sample(1:256, rep=T, 1000)
gene2 <- sample(1:256, rep=T, 1000)
sum(gene1 <= 128 & gene2 <= 128)
good_eaters <- sum(gene1 <= 128 & gene2 <= 128)
individual_evolving_groups <- good_eaters/2
individual_evolving_groups
